using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace Xfinity.GameEditor
{
    public partial class WeaponsEditor : Form
    {
        public WeaponsEditor()
        {
            InitializeComponent();
        }

        private void WeaponsEditor_Load(object sender, EventArgs e)
        {
            try
            {
                weapons.ReadXml(Nebulae.WeaponDatabaseStream);
            }
                // root node is missing, so write out a minimal xml file
                // slower than checking if the xml is valid, but i tonly has to happen once, so it's faster after the first run
            catch (XmlException)
            {
                weapons.WriteXml(Nebulae.WeaponDatabaseStream);
                weapons.ReadXml(Nebulae.WeaponDatabaseStream);                
            }
        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            weapons.WriteXml(Nebulae.WeaponDatabaseStream);
            cancelButton.Enabled = false;
        }

        private void weaponsGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            cancelButton.Enabled = true;
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            weapons.RejectChanges();
            cancelButton.Enabled = false;
        }

    }
}